package cn.com.dstz.agent.config;

import java.util.Map;

public class AdminConfig extends AgentConfig{

	
	public AdminConfig( Map< String, Object > admin, int count ){
		super( admin, count, AgentConfig.CONFIG_ADMIN  );
	}
	
	@Override
	public String getSQL( ) { 
		if( this.getReturnValue( ).equals( SELF )){
			valueMap.put( "aid", admin.get( "id" ) );
			return " and a.aid=:aid ";
		}else if( this.getReturnValue( ).equals( ALL ) ){
			valueMap.put( "topaid", admin.get( "topaid" ) );
			valueMap.put( "aid", admin.get( "id" ) );
			return " and a.topaid=:topaid and a.id !=:aid";
		}
		valueMap.put( "aid", admin.get( "topaid" ) );
		valueMap.put( "aid2", admin.get( "id" ) );
		valueMap.put( "self", admin.get( "id" ) );
		return getDefinedSQL( );
	}

	@Override
	public String getDefinedSQL( ) {
		
		String beginSQL = " and (a.aid in( select id from dstzadmin where";
		String endSQL = " and topaid = :aid ) or a.aid = :aid2 ) and a.id !=:self";
		
		return beginSQL +  super.getDefinedSQL( ) + endSQL ;
	}
	

	
}
